<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>减刑假释tab页</title>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css" />
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <link href="/webjars/miniui/css/demo.css" rel="stylesheet" type="text/css" />
    <link href="/static/css/default.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="mini-fit">
    <form id="form3" method="post">
        <input name="priNum" id="priNum" class="mini-hidden" value="${priNum!''}" readonly />
        <span style="font-size:16px; font-family: 宋体;line-height: 40px;font-weight: bold">减刑假释信息:</span>
        <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
            <table style="width:80%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button" iconCls="fa fa-plus" onclick="addJxjs()">增加</a>
                        <a class="mini-button" iconCls="fa-trash-o" onclick="removeJxjs()">撤销上次减刑</a>
                    </td>

                </tr>
            </table>
        </div>
        <div id="grid3" class="mini-datagrid" style="width:100%;height:700px;" sizeList="[5,10,20,30,40,50]" pageSize="20"
             showLoading="true"
             url="/azbj/yazgl/xxbl/jxjs/list?1=1&priNum=${priNum!''}" idField="id">
            <div property="columns">
                <div field="pName" width="10" headerAlign="center" align="center">姓名</div>
                <div field="subRange" width="10" headerAlign="center" align="center">现刑期类型</div>
                <div field="priStop" width="10" headerAlign="center" align="center" dateFormat="yyyy-MM-dd">现刑期止日</div>
                <div field="createTime" width="10" renderer="ondayRenderer" headerAlign="center" align="center">录入时间</div>
            </div>
        </div>
    </form>
</div>
</div>
<script type="text/javascript">
    mini.parse();
    var grid3 = mini.get("grid3");
    var priNum = mini.get("priNum");
    grid3.load();

    function addJxjs() {
        mini.open({
            url: "/azbj/yazgl/xxbl/jxjs/add?1=1" + "&priNum=${priNum!''}" + "&pristopold=${pristopold!''}",
            title: "录入减刑假释信息",
            width: 550,
            height: 450,
            onload: function () {
            },
            ondestroy: function (action) {
                window.location.reload();  //删除后刷新页面，使的页面加载最新的刑期止日。
                grid3.reload();
            }
        });
    }

    /**
     * 删除最新添加的一条数据，不给他选择删除
     * 因为这样做可以避免复杂的逻辑。
     */
    function removeJxjs() {
        var row = grid3.getData().length;
        if (row == 0) {
            mini.alert("请选中一条记录");
            return;
        }
        removeJxjs1();
    }

    function removeJxjs1() {
        var url = "/azbj/yazgl/xxbl/jxjs/delete?1=1" + "&priNum=${priNum!''}"+"&account=${account!''}";
        mini.confirm("确定要撤销吗？",
            "确定？",
            function (action) {
                if (action == "ok") {
                    $.ajax({
                        url: url,
                        type: 'POST',
                        cache: false,
                        async: false,
                        success: function (success) {
                            if (success.code == 1) {
                                mini.alert("撤销成功", '提示', function (){
                                    window.location.reload()
                                });
                            } else {
                                mini.alert("撤销失败");
                            }
                        },
                        error: function () {
                            mini.alert("操作失败!");
                        }
                    });
                }
            }
        )
    }

    /**
     * 格式化时间字符串
     * @param e
     * @returns {string}
     */
    function ondayRenderer(e) {
        var value = new Date(e.value);
        if (value) return mini.formatDate(value, "yyyy-MM-dd HH:mm:ss");
    }
</script>
</body>
</html>